
#include "struct_study.h"
#include <string.h>
#include <stdio.h>

#include <stdlib.h> //malloc(),free()

/**
 * 以下是互相引用的结构体
 */
struct Women_tag;//不完全类型 先仅申明标签
struct Man_tag {
     struct Women_tag *wife;
};
struct Women_tag 
{
     struct Man_tag *husband;
     
};

//另一种写法
typedef struct Women_tag Woman;
typedef struct {
     Woman *wife;
} Man;




double sum_struct(const struct funds * money){
     return (money->bankfund + money->savefund);
}

struct funds changeName(struct funds target){
     target.bankfund = target.bankfund+100;
     return target;

}

void getstruct_p_info(struct funds_p *pst){
     char temp[81] ="teststtt";
     pst->bank = (char *)malloc(strlen(temp)+1);
     strcpy(pst->bank,temp);//把字符串拷贝到已分配的内存中
     // char temp2[81];
     printf("please input you words:\n");
     s_gets2(temp,81);
     pst->save = (char *)malloc(strlen(temp)+1);
     strcpy(pst->save,temp);

   

}
//释放指针指向的内存
void cleanup(const struct funds_p *pst){
     free(pst->bank);
     free(pst->save);

}

char * s_gets2(char *st,int n){
     char * ret_val;
     int i=0;
     char *find;

     ret_val = fgets(st,n,stdin);
     if (ret_val)
     {
          find = strchr(st,'\n');//查找换行符
          if (find) //如果地址不是null，说明找到了换行符

          {
               *find ='\0';//此处放置一个空字符
          }else{
               while (getchar()!= '\n')
               {
                    continue;
               }
          }
          

          // while (st[i] != '\n' && st[i] != '\0')
          // {
          //      i++;
          // }
          // if (st[i] == '\n')
          // {
          //     st[i] = '\0';
          // }

          // else {
          //      while (getchar() != '\n')
          //      {
          //           continue;
          //      }
               
          // }
          
          
     }

     return ret_val;
     
}



